PROJECT(all)
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)

SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

# Check depend library

INCLUDE(FindPCAP)
IF(PCAP_FOUND)
    ADD_DEFINITIONS(-DHAS_PCAP)
ENDIF(PCAP_FOUND)

INCLUDE(FindDNET)
IF(DNET_FOUND)
    ADD_DEFINITIONS(-DHAS_DNET)
ENDIF(DNET_FOUND)

INCLUDE(FindDaemon)
IF(DAEMON_FOUND)
    ADD_DEFINITIONS(-DHAS_DAEMON)
ENDIF(DAEMON_FOUND)

MESSAGE(STATUS "We have a ${CMAKE_SYSTEM} system")
IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
	SET(GENERIC_FLAGS "${GENERIC_FLAGS} -fPIC")
	IF(DEFINED SOCKREACTOR)
		ADD_DEFINITIONS(-D${SOCKREACTOR})
	ELSE(DEFINED SOCKREACTOR)
		ADD_DEFINITIONS(-DNET_KQUEUE)
	ENDIF(DEFINED SOCKREACTOR)
	STRING(TOLOWER ${CMAKE_SYSTEM} TEMP_CMAKE_SYSTEM)
	STRING(REGEX MATCH "kfreebsd*" TEMP_CMAKE_SYSTEM_MATCH ${TEMP_CMAKE_SYSTEM})
	IF(TEMP_CMAKE_SYSTEM_MATCH MATCHES "kfreebsd")
		ADD_DEFINITIONS(-DDFREEBSD)
	ELSE(TEMP_CMAKE_SYSTEM_MATCH MATCHES "kfreebsd")
		ADD_DEFINITIONS(-DFREEBSD)
		INCLUDE(cmake_find_modules/Find_execinfo.cmake)
	ENDIF(TEMP_CMAKE_SYSTEM_MATCH MATCHES "kfreebsd")
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Darwin")
	SET(GENERIC_FLAGS "${GENERIC_FLAGS} -mmacosx-version-min=10.5")
	ADD_DEFINITIONS(-MACOSX)
	IF(DEFINED SOCKREACTOR)
		ADD_DEFINITIONS(-D${SOCKREACTOR})
	ELSE(DEFINED SOCKREACTOR)
		ADD_DEFINITIONS(-DNET_KQUEUE)
	ENDIF(DEFINED SOCKREACTOR)
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
	SET(GENERIC_FLAGS "${GENERIC_FLAGS} -fPIC")
	ADD_DEFINITIONS(-DLINUX)
	IF(DEFINED SOCKREACTOR)
		ADD_DEFINITIONS(-D${SOCKREACTOR})
	ELSE(DEFINED SOCKREACTOR)
		ADD_DEFINITIONS(-DNET_EPOLL)
	ENDIF(DEFINED SOCKREACTOR)
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
	SET(GENERIC_FLAGS "${GENERIC_FLAGS} -fPIC")
	ADD_DEFINITIONS(-DSOLARIS)
	ADD_DEFINITIONS(-DDONT_DEFINE_HTONLL)
	ADD_DEFINITIONS(-DNET_SELECT)
	SET(SOCKET_LIB "-lsocket")
ELSE(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
	MESSAGE(FATAL_ERROR "Platform ${CMAKE_SYSTEM_NAME} not supported yet")
ENDIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")

# config.h
#
# add_definitions(-DHAVE_CONFIG_H)
#
# message(STATUS "Parsing 'config.h.cmake'")
# configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/config.h")

ADD_SUBDIRECTORY(src)
